let pool=require('./db')
async function getUser() {
  try {
    const [rows] = await pool.execute('SELECT * FROM user');
    return rows;
  } catch (err) {
    console.error('查询用户失败:', err);
    throw err;
  }
}
// 新增：通过用户名获取单个用户（用于登录验证）
async function getUserByUsername(username) {
  try {
    const [rows] = await pool.execute(
      'SELECT user_id, username, password FROM user WHERE username = ?', 
      [username]
    );
    return rows[0]; // 返回单个用户对象或 undefined
  } catch (err) {
    console.error('查询单个用户失败:', err);
    throw err;
  }
}
module.exports = { getUser,getUserByUsername };